package wlpc;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class recive {
    public static void main(String[] args) throws IOException {
        //与前面的发送的端口保持一致
        DatagramSocket ds = new DatagramSocket(10086);

        byte[] bytes = new byte[1024];

        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
        ds.receive(dp);

        //解析数据
        byte[] by = dp.getData();
        int len = by.length;
        //端口
        int port = dp.getPort();

        InetAddress address = dp.getAddress();

        System.out.println(new String(by,0,len));
        System.out.println("从端口："+port+"从地址："+address);
        ds.close();

    }
}
